-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: add stream hook function for ChatAgent.step() & ChatAgent.astep() #3184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Wendong-Fan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @karboom for opening this PR,
After reviewing the PR in detail, I have concerns about the design. Users can already achieve the same result by iterating over the streaming response using code below:
# Without stream_hook (current way)
for chunk in agent.step(message):
# Do something with chunk - push to websocket, queue, etc.
handle_chunk(chunk)
The hook seems doesn't provide significant value over normal iteration. And adding the hook would make the ChatAgent is being given responsibility for side effects that should be the caller's responsibility. This mixes business logic with agent behavior.
If callbacks are needed, a proper observer/event system would be
better (like on_chunk, on_complete, on_error with event emitters).
Adding the hook will also make it be called with:
- ChatAgentResponse for chunks
- BaseMessage for final messages (in some paths)
- ChatAgentResponse for errors
This inconsistency makes it hard to use correctly.
I think it would be better to keep original design, WDYT?
|
thanks @karboom , now we have callback system for better observer, here is the example file: examples/workforce/workforce_callbacks_example.py, now it's not supporting streaming mode, I created one issue for adding this support here: #3379 , feel free to check and leave your comment |
Description
Sometimes, we need to obtain real-time responses from multiple agents. This hook function can output real-time responses to the frontend through websocket or perform other operations
Checklist
Fixes #issue-numberin the PR description (required)pyproject.tomlanduv lock